import { createStore } from 'vuex'
const SessionStorage = {
  get: function (key) {
    var v = sessionStorage.getItem(key);
    if (v && typeof(v) !== "undefined" && v !== "undefined") {
      return JSON.parse(v);
    }
  },
  set: function (key, data) {
    sessionStorage.setItem(key, JSON.stringify(data));
  },
  remove: function (key) {
    sessionStorage.removeItem(key);
  },
  clearAll: function () {
    sessionStorage.clear();
  }
};
const USER = "USER";

const store = createStore({
  state: {
    user: SessionStorage.get(USER) || {}
  },
  getters: {
  },
  mutations: {
    setUser(state,user){
      state.user = user
      // console.log('setUser',user)
      SessionStorage.set(USER, user);
      console.log('state.user',state.user)
    },
    setUserAvatar(state,base64){
      state.user.base64Data = base64
      SessionStorage.set(USER, state.user);
    }
  },
  actions: {
  },
  modules: {
  }
})

export default store
